--TEST--
int MySQLndUhConnection::getAffectedRows(resource $connection)
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
	require_once('config.inc');

	class proxy extends MySQLndUhConnection {
		public function getAffectedRows($res) {
			printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));
			var_dump($ret = parent::getAffectedRows($res));
			return $ret;
		}
	}

	class proxy2 extends MySQLndUhConnection {
		public function getAffectedRows($res) {
			return 12;
		}
	}

	class proxy3 extends MySQLndUhConnection {
		public function getAffectedRows($res) {
			$ret = new stdClass();
			return $ret;
		}
	}

	class proxy4 extends MySQLndUhConnection {
		public function getAffectedRows($res) {}
	}

	class proxy5 extends MySQLndUhConnection {
		public function getAffectedRows($res) {
			return PHP_INT_MAX;
		}
	}

	function test_affected($conn, $offset, $insert_rows, $num_rows) {

		if (!$conn->query("DELETE FROM test")) {
			printf("[%03d + 1] [%d] '%s'\n", $offset, $conn->errno, $conn->error);
			return false;
		}

		$in = '';
		for ($i = 0; $i < $insert_rows; $i++) {
			$in .= sprintf("%d, ", $i);
			if (!$conn->query(sprintf("INSERT INTO test(col1) VALUES (%d)", $i))) {
				printf("[%03d + 2] [%d] '%s'\n", $offset, $conn->errno, $conn->error);
				return false;
			}
		}
		$in = substr($in, 0, -2);

		if ((1 != $conn->affected_rows) && ($num_rows != $conn->affected_rows)) {
			printf("[%03d + 3] Expecting 1 or %d got %s\n", $offset, $num_rows, $conn->affected_rows);
			return false;
		}

		if (!$conn->query(sprintf("DELETE from test WHERE col1 IN (%s)", $in))) {
			printf("[%03d + 4] [%d] '%s'\n", $offset, $conn->errno, $conn->error);
			return false;
		}

		if ($num_rows != $conn->affected_rows) {
			printf("[%03d + 3] Expecting %d got %s\n", $offset, $num_rows, $conn->affected_rows);
			return false;
		}

		return true;
	}

	$conn = mysqlnd_uh_test\connect::mysqli();
	mysqlnd_uh_test\query_test::mysqli($conn);
	if (!$conn->query("DROP TABLE IF EXISTS test")
		|| !$conn->query("CREATE TABLE test(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, col1 INT)"))
		printf("[001] [%d] '%s'\n", $conn->errno, $conn->error);

	test_affected($conn, 2, 2, 2);
	mysqlnd_uh_test\query_test::mysqli($conn);

	mysqlnd_uh_set_connection_proxy(new proxy());
	test_affected($conn, 3, 1, 1);
	mysqlnd_uh_test\query_test::mysqli($conn);

	mysqlnd_uh_set_connection_proxy(new proxy2());
	test_affected($conn, 4, 2, 12);
	mysqlnd_uh_test\query_test::mysqli($conn);

	mysqlnd_uh_set_connection_proxy(new proxy3());
	test_affected($conn, 5, 3, 3);
	mysqlnd_uh_test\query_test::mysqli($conn);

	mysqlnd_uh_set_connection_proxy(new proxy4());
	test_affected($conn, 6, 1, 0);
	mysqlnd_uh_test\query_test::mysqli($conn);

	mysqlnd_uh_set_connection_proxy(new proxy5());
	test_affected($conn, 7, 2, PHP_INT_MAX);
	mysqlnd_uh_test\query_test::mysqli($conn);

	print "done!";
?>
--EXPECTF--
proxy::getAffectedRows(array (
  0 => NULL,
))
int(1)
proxy::getAffectedRows(array (
  0 => NULL,
))
int(1)

Warning: test_affected(): (MySQLnd User Handler) The method MySQLndUhConnection::getAffectedRows() did not return a numeric value as it should (C type used by mysqlnd: "uint64_t") in %s on line %d

Warning: test_affected(): (MySQLnd User Handler) The method MySQLndUhConnection::getAffectedRows() did not return a numeric value as it should (C type used by mysqlnd: "uint64_t") in %s on line %d

Warning: test_affected(): (MySQLnd User Handler) The method MySQLndUhConnection::getAffectedRows() did not return a numeric value as it should (C type used by mysqlnd: "uint64_t") in %s on line %d

Warning: test_affected(): (MySQLnd User Handler) The method MySQLndUhConnection::getAffectedRows() did not return a numeric value as it should (C type used by mysqlnd: "uint64_t") in %s on line %d

Warning: test_affected(): (MySQLnd User Handler) The method MySQLndUhConnection::getAffectedRows() did not return a numeric value as it should (C type used by mysqlnd: "uint64_t") in %s on line %d

Warning: test_affected(): (MySQLnd User Handler) The method MySQLndUhConnection::getAffectedRows() did not return a numeric value as it should (C type used by mysqlnd: "uint64_t") in %s on line %d
done!